package com.example.dee.dao;

import com.example.dee.pojo.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @ClassName SysDAO
 * @创建人 李劲松
 * @创建时间 2022/7/20 10:25
 * @描述 A机构管理员操作与数据库交互
 */
@Mapper
@Repository
public interface SysDAO {

    @Update("update t_car_data set state = #{state}, t_car_data.desc = #{desc}, t_car_data.upTime = #{date} where id = #{id}")
    void updateCarDataState(String id, String state,String desc,String date);

    @Insert("insert into t_car_data(id, enTime, enTollStationName, exTime, exTollStationName, vehicleId,vehicleType, fee) values(#{id}, #{enTime}, #{enTollStationName}, #{exTime}, #{exTollStationName}, #{vehicleId},#{vehicleType}, #{fee})")
    int  addCarData(String id, String enTime, String enTollStationName, String exTime, String exTollStationName, String vehicleId,int vehicleType, Double fee);

    @Delete("delete from t_car_data where id = #{id}")
    int deleteCarData(String id);

    @Select("select serialData from t_global_param where id = 1")
    String selectSerialData();

    @Select("select serial from t_global_param where id = 1")
    int selectSerial();

    @Update("update t_global_param set serial = #{serial} , serialData = #{serialData} where id = 1")
    void updateSerial(int serial, String serialData);


    @Select("select * from t_car_data where id = #{id}")
    CarData selectCarData(String id);
    @Select("select * from t_car_data where state = #{state} order by upTime desc")
    List<CarData> selectCarDataByState(String state,int begin,int showNum);
    @Select("select * from t_car_data where state != '1' order by upTime desc")
    List<CarData> selectCarDataByUp(int begin,int showNum);

    @Select("select * from t_car_data order by upTime desc")
    List<CarData> selectCarDataAll();
    @Select("select command from t_global_param where id = 1")
    String selectCommand();

    @Update("update t_global_param set command = #{command} where id = 1")
    int updateCommand(String command);

    @Insert("insert into t_car_record(carDataId,enTime,enTollStationName,exTime,exTollStationName,vehicleId,vehicleType,fee,state,t_car_record.desc,t_car_record.func,t_car_record.time,sysId) values(#{id},#{enTime},#{enTollStationName},#{exTime},#{exTollStationName},#{vehicleId},#{vehicleType},#{fee},#{state},#{desc},#{func},#{date},#{sysId})")
    int addCarRecord(String id, Date enTime, String enTollStationName, Date exTime, String exTollStationName, String vehicleId, String vehicleType, double fee, String state,String desc, String func, Date date, int sysId);
    @Insert("insert into t_record(id,enTime,enTollStationName,exTime,exTollStationName,vehicleId,vehicleType,fee,upDesc,receiveDesc,upTime,sysId) values(#{id},#{enTime},#{enTollStationName},#{exTime},#{exTollStationName},#{vehicleId},#{vehicleType},#{fee},#{upDesc},#{receiveDesc},#{upTime},#{sysId})")
    int addRecord(String id, Date enTime, String enTollStationName, Date exTime, String exTollStationName, String vehicleId, String vehicleType, double fee, String upDesc, String receiveDesc, Date upTime, int sysId);

    @Update("update t_record set receiveDesc = #{info} where id = #{id}")
    int updateRecord(String info,String id);

    @Select("select * from t_record order by upTime desc limit #{begin} ,#{showNum}")
    List<Record> selectRecord(String today,int begin,int showNum);

    @Select("select * from t_car_record order by time desc limit #{begin} ,#{showNum}")
    List<CarRecord> selectCarRecord(String today,int begin,int showNum);

    @Update("update t_car_data set fee = #{fee},state = '2',upTime =#{upTime},t_car_data.desc = #{desc} where id = #{id}")
    int updateCarData(String id, Double fee,Date upTime,String desc);

    @Select("select count(*) from ${table}")
    int getCountByTable(String table);
}
